 // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
 // Jad home page: http://www.kpdus.com/jad.html
 // Decompiler options: packimports(3) 
 // Source File Name:   FileDirectory.java

 package com.jb.web.bean.custom;

 import com.jb.faces.context.FacesContext;
 import com.jb.faces.el.AttributeEvaluator;
 import com.jb.web.application.EventManager;
 import com.jb.web.bean.JBTreeNode;
 import com.jb.web.bean.WebTree;
 import com.jb.web.bean.event.UIEvent;
 import com.jb.web.context.WebContext; 
 import com.jb.web.session.SessionUser;
 import java.io.File;
 import java.util.List;
 import javax.servlet.jsp.el.ELException;

 // Referenced classes of package com.jb.web.bean.custom:
 //            FileNode, FileListModel

 public class FileDirectory extends WebTree
 {

     private void $init$()
     {
         listModel = new FileListModel();
     }

     public void setDatabase(boolean database)
     {
         this.database = database;
     }

     public boolean isDatabase()
     {
         return database;
     }

     public FileNode getFile()
     {
         return file;
     }

     public void setFileFilters(String fileFilters)
     {
         if(fileFilters != null && !fileFilters.equals(this.fileFilters))
         {
             this.fileFilters = fileFilters;
             refresh((WebContext)getFacesContext());
         }
     }

     public String getFileFilters()
     {
         return fileFilters;
     }

     public void setFileList(List list)
     {
         fileList = list;
     }

     public List getFileList()
     {
         return fileList;
     }

     public void setFileLocation(String loc)
     {
         fileLocation = loc;
     }

     public String getFileLocation()
     {
         return fileLocation;
     }

     public void setListModel(FileListModel listModel)
     {
         this.listModel = listModel;
     }

     public FileListModel getListModel()
     {
         return listModel;
     }

     public void setOwner(SessionUser owner)
     {
         this.owner = owner;
     }

     public SessionUser getOwner()
     {
         return owner;
     }

     public void setReadOnly(boolean readOnly)
     {
         this.readOnly = readOnly;
     }

     public boolean isReadOnly()
     {
         return readOnly;
     }

     public void setRecursive(boolean recursive)
     {
         this.recursive = recursive;
     }

     public boolean isRecursive()
     {
         return recursive;
     }

     public void setSelected(int i)
     {
         selected = fileList == null || fileList.size() <= i ? selected : (FileNode)fileList.get(i);
     }

     public FileNode getSelected()
     {
         if(selected == null && fileList != null && fileList.size() > 0)
             selected = (FileNode)fileList.get(0);
         return selected;
     }

     public void setShowFile(boolean showFile)
     {
         this.showFile = showFile;
     }

     public boolean isShowFile()
     {
         return showFile;
     }

     public void changeModel()
     {
         if(fileLocation != null)
         {
             WebContext ctx = (WebContext)getFacesContext();
             try
             {
                 if(ctx != null)
                 {
                     String uri = (String)AttributeEvaluator.evaluate(ctx, this, fileLocation);
                     setModel(ctx, FileNode.getFileTreeModel(ctx.getWebTop(), uri, showFile, getFileFilters()));
                     getRootNode().addSelectListner(this);
                     file = (FileNode)getRootNode().getSelectedNode().getUserObject();
                     file.setTitle(getValue());
                     listModel.setFileLocation(uri);
                     refresh(ctx);
                 }
             }
             catch(ELException e)
             {
                 ctx.addErrorMessage(this, (new StringBuilder()).append("Failed to evaluate ").append(fileLocation).toString());
                 setModel(ctx, FileNode.getFileTreeModel(fileLocation, "", showFile, getFileFilters()));
             }
         }
     }

     public void invalidate()
     {
         file.invalidate();
     }

     public void onSelect(WebContext ctx, UIEvent event)
     {
         super.onSelect(ctx, event);
         JBTreeNode node = (JBTreeNode)event.getSource();
         file = (FileNode)node.getSelectedNode().getUserObject();
         listModel.setFileLocation((new StringBuilder()).append(file.getFileLocation()).append(File.separator).append(file.getFile().getName()).toString());
         refresh(ctx);
         if(getOnSelectNode() != null)
             EventManager.getInstance().handleEvent(ctx, this, getOnSelectNode());
     }

     public void processUpdates(FacesContext ctx)
     {
         super.processUpdates(ctx);
         if(owner == null)
             owner = ((WebContext)ctx).getSession().getUser();
         if(getRootNode() == null)
             changeModel();
     }

     public void refresh(WebContext ctx)
     {
         if(ctx == null)
             return;
         if(database)
             file.setModel(listModel);
         if(file == null)
         {
             return;
         } else
         {
             file.invalidate();
             fileList = file.getFiles(ctx, fileFilters);
             selected = file;
             return;
         }
     }

     public FileDirectory()
     {
         $init$();
     }

     static final long serialVersionUID = 0x1e0f3L;
     FileListModel listModel;
     private transient FileNode file;
     private transient FileNode selected;
     private transient List fileList;
     private transient SessionUser owner;
     private String fileFilters;
     private String fileLocation;
     private boolean database;
     private boolean readOnly;
     private boolean recursive;
     private boolean showFile;

     static 
     {
         publish(FileDirectory.class, "General", "fileLocation");
         publish(FileDirectory.class, "General", "fileFilters");
         publish(FileDirectory.class, "General", "showFile");
         publish(FileDirectory.class, "General", "database");
         publish(FileDirectory.class, "General", "recursive");
     }
 }
